<template>
    <Teleport to="body">
        <transition name="el-fade-in">
            <div
                class="task-list-dialog"
                v-if="dialogStore.isTaskListDialogVisible"
            >
                <div class="task-list-dialog__mask" @click="onClose"></div>
                <div class="task-list-dialog__content">
                    <div class="task-list-dialog__close" @click="onClose">
                        <img :src="`${_oss_}images/icon-close-black.svg`" />
                    </div>

                    <div class="task-list-dialog__title">
                        <div class="title">任务列表</div>
                        <div class="score-title">
                            (当前积分：{{ userStore.midNum.score_num }})
                        </div>
                    </div>

                    <div class="task-list-dialog__list">
                        <div
                            class="task-list-dialog__item"
                            v-for="item in list"
                            :key="item.code"
                        >
                            <div class="task-item__title">
                                {{ item.title }}({{ item.user_times }}/{{
                                    item.times
                                }})
                            </div>
                            <div class="task-item__score">
                                +{{ item.score }}积分
                            </div>
                            <div
                                class="task-item__btn"
                                :class="{
                                    'task-item__btn-disabled':
                                        item.user_times >= item.times,
                                }"
                                @click="onGoToScoreAction(item)"
                            >
                                {{
                                    item.user_times >= item.times
                                        ? item.code == 1000
                                            ? "已签到"
                                            : "已完成"
                                        : item.code == 1000
                                        ? "签到"
                                        : "去完成"
                                }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </Teleport>
</template>
<script setup>
import { useContent } from ".";

const dialogStore = useDialogStore();
const userStore = useUserStore();
const { list, onClose, onGoToScoreAction } = useContent();
</script>
<style lang="scss" scoped>
.task-list-dialog {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999;

    &__mask {
        position: relative;
        width: 100%;
        height: 100%;
        background-color: rgba($color: #000000, $alpha: 0.5);
    }

    &__content {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 350px;
        background-color: #fff;
        transform: translate(-50%, -50%);
        border-radius: 10px;
    }

    &__title {
        display: flex;
        align-items: flex-end;
        padding: 14px 0 14px 14px;
        color: #333;

        .title {
            font-size: 16px;
        }

        .score-title {
            font-size: 12px;
            margin-left: 10px;
        }
    }

    &__list {
        padding: 0 14px 10px;
        max-height: 80vh;
        overflow: auto;
    }

    &__item {
        display: flex;
        align-items: center;
        padding: 14px 0;
        border-bottom: 1px solid #ddd;

        .task-item__title {
            color: #333;
            font-size: 14px;
        }

        .task-item__score {
            font-size: 14px;
            margin-left: auto;
            margin-right: 10px;
            color: #5085fb;
        }

        .task-item__btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            background: #5085fb;
            font-size: 14px;
            width: 70px;
            height: 26px;
            border-radius: 20px;
            cursor: pointer;
            user-select: none;

            &-disabled {
                pointer-events: none;
                cursor: default;
                background: #adc6ff;
            }
        }
    }

    &__close {
        position: absolute;
        top: 14px;
        right: 14px;
        cursor: pointer;

        img {
            width: 18px;
            height: 18px;
        }
    }
}
</style>
